<template>
  <div>
    <!-- 搭建基本布局  el-container -->
    <el-container>
      <el-header height="80px">****大型后台管理系统
        <div>
          用户名：<span>{{ username }}</span>
          <el-button @click="logout" type="danger" size="small">退出</el-button>
        </div></el-header
      >
      <el-container>
        <el-aside width="220px">
          <v-nav></v-nav>
        </el-aside>
        <el-main>
          <!-- 二级路由出口 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template> 

<script>
import vNav from "../components/vNav.vue";
export default {
  data() {
    return {
      username: "",
    };
  },
  mounted() {
    this.username = JSON.parse(sessionStorage.getItem("userinfo")).username;
  },
  methods: {
    //封装一个退出事件
    logout(){
      // 退出的逻辑有两个步骤
      /* 
        // 1.清空你的存储内容
        // sessionStorage.removeItem('userinfo')
      */
      // 1.清空你的存储内容(在这里重新触发行动)
      this.$store.dispatch('changeUser',false)
      //2.跳转到登录页
      this.$router.push('/login')
    }
  },
  components: {
    vNav,
  },
};
</script>

<style scoped>
.el-header {
  background-color: rgb(48, 224, 255);
  text-align:center;
  font-size: 22px;
}
.el-header div{
  margin: 20px;
  float: right;
}
</style>